package com.gzy.blog.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gzy.blog.sys.dao.LogDao;
import com.gzy.blog.sys.dao.UserDao;
import com.gzy.blog.sys.entity.User;
import com.gzy.blog.sys.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;
	@Autowired
	private LogDao logDao;

	/**
	 * 新增一个用户，并记录日志
	 */
	@Override
	// @Transactional
	// @Transactional(propagation = Propagation.REQUIRED)
	public void add(User user) {
		userDao.addUser(user);
		logDao.addLog();
	}

	/**
	 * <pre>
	 * &#64;Transactional的配置
	 * propagation  默认为required，也是用得最多的
	 * readOnly     默认为false，设置为true表示只做查询（可提高查询效率）
	 * </pre>
	 */
	@Override
	// @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public User get(Integer id) {
		return userDao.getUser(id);
	}

	@Override
	public User login(User user) {
		// TODO Auto-generated method stub
		return userDao.login(user);
	}

	@Override
	public List<User> listUser() {
		// TODO Auto-generated method stub
		return userDao.listUser();
	}

	@Override
	public void delete(User user) {
		// TODO Auto-generated method stub
		userDao.delete(user);
	}

	@Override
	public void update(User user) {
		// TODO Auto-generated method stub
		userDao.update(user);
	}

}
